/**
 * @author homepagecn@gmail.com
 * @version $Id: room.js 13 2011-11-30 09:54:29Z homepagecn@gmail.com $
 */
var max_room = 100;
var max_user = 4;
var rooms = {};
exports.join = function(uid, room_id, option){
        if(room_id < 0 || room_id > max_room){
            return false;
        }
        if(typeof(rooms[room_id]) == 'undefined'){
            var room = {user : {}, status : 1, user_num : 0};
        }else{
            var room = rooms[room_id];
        }
        if(room.status == 2){
            return false;
        }
        if(typeof(option) == 'undefined'){
            var option = {};
        }
        var user = option;
        user.uid = uid;
        room.user[uid] = user;
        room.user_num++;
        if(room.user_num == max_user){
            room.status = 2;
        }
        return true;
    }
exports.park = function(uid, room_id){
        if(room_id < 0 || room_id > max_room){
            return false;
        }
        if(typeof(rooms[room_id]) == 'undefined'){
            return false;
        }else{
            var room = rooms[room_id];
            if(typeof(room.user[uid]) == 'undefined'){
                return false;
            }
        }
        delete room.user[uid];
        room.user_num--;
        room.status = 1;
    }